#define _CRT_SECURE_NO_WARNINGS 1
#include <string>
#include <iostream>
using namespace std;

class Solution {
public:
	string replaceSpace(string s) {
		int cnt = 0;
		int n = s.size();
		for (size_t i = 0; i<n; i++)
		{
			if (s[i] == ' ')
			{
				cnt++;
			}
		}

		int newsize = n + 2 * cnt;
		int new_index = newsize - 1;
		int old_index = n - 1;
		s.resize(newsize);
		while (old_index >= 0 && new_index >= 0)
		{
			if (s[old_index] == ' ')
			{
				s[new_index--] = '0';
				s[new_index--] = '2';
				s[new_index] = '%';
			}
			else
			{
				s[new_index] = s[old_index];
			}
			old_index--;
			new_index--;
		}
		return s;
	}
};


int main()
{
	string s1("we are happy");
	Solution s;
	cout << s.replaceSpace(s1)<<endl;
	return 0;
}